// Soup Icon Constants

DefConst('kUserSoupName, "WriteHere Clipboard");
DefConst('kSoupPackageName, "Soups:" & kPackageName);

DefConst('kExtraIconParamFrame, {	soupNames: [kSoupName],
									text: kUserSoupName,
									ownerApp: kAppSymbol,
									app: kAppSymbol,
								});
								
/* kInstallFunc
 * ------------
 * Installs the option auxillary buttons in either the
 * NotePad or the current background application. Auto-opens
 * the application if the preference is checked.
 *
 */
 
SetPartFrameSlot('kInstallFunc, func() begin
	local prefs := GetAppPrefs(kAppSymbol, kPrefsFrame);
	local ed := GetRoot().extrasDrawer;
	local theStore := GetStores()[0];

	if prefs then begin
		if prefs.backgroundButton then RegAuxButton(kAppSymbol, kMyAuxButton);
		if prefs.notepadButton then RegAuxButton(kAppSymbol, kMyNotepadAuxButton);
		if prefs.autoOpen then AddDeferredCall(func() GetRoot().(kAppSymbol):open(), nil);
	end;
	try begin
		local newtWorks := GetRoot().newtWorks;
		
		if newtWorks then begin
			newtWorks:RegNewtWorksTool('|WriteHere:Paper:ATOW|, kNewtWorksTool);
			newtWorks:RegNewtWorksTool('|WriteHere:DrawPaper:ATOW|, kDrawNewtWorksTool);
		end;
		
		if Length(ed:GetExtraIcons('SoupEntry, kSoupPackageName, theStore)) = 0 then
			call kAddExtraIconFunc with ('SoupEntry, kExtraIconParamFrame, kSoupPackageName, theStore);
	end
	onexception |evt.ex| do nil;
	
	AddDeferredAction(func() GetRoot().(kAppSymbol):Open(), []);
end);



InstallScript := func(partFrame)
begin
	AddDeferredCall(partFrame.kInstallFunc, nil);
end;


	// RemoveScript: Unregisters all auxillary buttons

RemoveScript := func(packageFrame) begin
	if (newtWorks := GetRoot().newtWorks) then begin
		newtWorks:UnregNewtWorksTool('|WriteHere:Paper:ATOW|);
		newtWorks:UnregNewtWorksTool('|WriteHere:DrawPaper:ATOW|);
	end;
		
	UnRegAuxButton(EnsureInternal(kAppSymbol));
end;


	// DeletionScript

SetPartFrameSlot('DeletionScript, func() begin
	local ed := GetRoot().extrasDrawer;
	local theStore := GetStores()[0];
	
	foreach icon in ed:GetExtraIcons('SoupEntry, kSoupPackageName, theStore) do
		ed:RemoveExtraIcon(icon);
	end
);